package xyz.showbooks.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.dfm.pojo.User;
import xyz.showbooks.service.UserService;

import java.util.List;


/**
 * 此类提供用户相关接口
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 根据id查询用户
     * @param userId
     * @return
     */
    @GetMapping("/findId/{userId}")
    public User findUserById(@PathVariable Integer userId){
        return userService.findUserById(userId);
    }


    /**
     * 通过模糊name查找用户
     */
    @GetMapping("/findUserByName/{name}/{start}/{size}")
    public List<User> findUserByName(@PathVariable String name,@PathVariable Integer start,@PathVariable Integer size){
        return userService.findUserByName(name, start, size);
    }

    //通过模糊number查找用户
    @GetMapping("/findUserByNumber/{number}/{start}/{size}")
    public List<User> findUserByNumber(@PathVariable String number,@PathVariable Integer start,@PathVariable Integer size){
        return userService.findUserByNumber(number,start,size);
    }

    //通过状态查找用户
    @GetMapping("/findUserByStatus/{status}/{start}/{size}")
    public List<User> findUserByStatus(@PathVariable String status,@PathVariable Integer start,@PathVariable Integer size){
        return userService.findUserByStatus(status,start,size);
    }


    @PutMapping("/updateUser")
    public void updateUser(@RequestBody User user){
        userService.updateUser(user);
    }
    //...
}
